/**
 * Created by QianQi on 2017/6/13.
 */
$(function(){
    var oHideParams = $.getHideParams();// <body> 下隐藏域键值对，name 为键
    var oUrlParams = $.getUrlParams();// url 附加参数键值对
    var URLS = {
        p_layer: 'demo_layer.html'  // 弹出页面
    };
    var jqCont = $('.js-cont'),
        oLayerApi;// 弹出框 api
    // 顶部按钮点击事件
    var fTbtnsClick = function(){
        var jqThis = $(this),
            type = jqThis.attr('data-type');
        switch (type){
            case 'btn0':// 与 btn1 执行相同的操作
            case 'btn1':
                oLayerApi.show({
                    data: {// 向弹出框传递参数
                        name: type
                    }
                });
                break;
            case 'special':
                oLayerApi.show({
                    layerOpts:{
                        title: '特殊的弹框!!'
                    },
                    callback: function(){
                        alert('特殊的弹框回调');
                    },
                    data: {// 向弹出框传递参数
                        name: '特殊按钮'
                    }
                });
                break;
        }
    };
    // 弹出框回调
    var fLayerCb = function(data){
        jqCont.prepend('<div>'+ data.text +'</div>');
    };
    /** ============== **/
    $('.js-tbtns').on('click','button',fTbtnsClick);// 顶部按钮点击事件
    oLayerApi = $.initWiLayer({
        name: 'layer',
        //win: window,// 实际弹框的窗口
        layerOpts:{
            content:URLS.p_layer,
            title:'我是弹出框',
            area:['80%','80%']
        },
        callback: fLayerCb
    });
});